package org.mics.cyy.backUser.controller;

import java.util.List;

import javax.annotation.Resource;

import org.mics.core.page.PageQuery;
import org.mics.core.response.MultipleDataResponse;
import org.mics.core.response.OneDataResponse;
import org.mics.core.response.PageDataResponse;
import org.mics.core.response.SimpleResponse;
import org.mics.cyy.backUser.entity.RoleDO;
import org.mics.cyy.backUser.request.RoleRequest;
import org.mics.cyy.backUser.service.RoleService;
import org.mics.cyy.backUser.vo.RoleVO;
import org.mics.lang.bean.BeanConvertUtil;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

/**
 * 角色
 * @author mics
 * @date 2020年6月10日
 * @version  1.0
 */
@RestController
@RequestMapping("/role")
@Tag(name = "角色")
public class RoleController {
	@Resource
	private RoleService roleService;
	
	@Operation(summary =  "增加/修改角色")
    @RequestMapping(value = "/save",method = RequestMethod.POST)
	public SimpleResponse save(@Validated @RequestBody RoleRequest roleRequest ) {
		String id =   roleService.add(roleRequest);
		return new OneDataResponse<String>(id);
	}
	
	@Operation(summary =  "删除角色")
    @RequestMapping(value = "/delete/{id}",method = RequestMethod.DELETE)
	public SimpleResponse delete(@PathVariable("id") String id) {
		roleService.delete(id);
        return new SimpleResponse();
	}
	
	@Operation(summary =  "角色分页列表")
    @RequestMapping(value = "/listByPage",method = RequestMethod.POST)
	public PageDataResponse<RoleVO> listByPage(@RequestBody PageQuery pageQuery) {
		PageDataResponse<RoleVO> pageDataResponse =   roleService.listByPage(pageQuery);
		return pageDataResponse;
	}
	
	@Operation(summary =  "角色列表")
    @RequestMapping(value = "/list",method = RequestMethod.GET)
	public MultipleDataResponse<RoleVO> list() {
		List<RoleDO> roleDOs =   roleService.list();
		return new MultipleDataResponse<RoleVO>(BeanConvertUtil.convertList(roleDOs, RoleVO.class));
	}
}
